package solutions.leetcode.easy;

import solutions.lib.TreeNode;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/range-sum-of-bst/">938. 二叉搜索树的范围和</a>
 */
public class Solution938 {

    public int rangeSumBST(TreeNode root, int low, int high) {
        if (root == null) {
            return 0;
        }
        int sum = 0;
        if (root.val >= low && root.val <= high) {
            sum = root.val;
        }
        if (root.val < high) {
            sum += rangeSumBST(root.right, low, high);
        }
        if (root.val > low) {
            sum += rangeSumBST(root.left, low, high);
        }
        return sum;
    }

    public static void main(String[] args) {
        Solution938 solution = new Solution938();
    }
}